<template>
	<view>
		<view v-if="opt.file">
			<video style="width: 100%;" id="myVideo" :src="opt.file" @error="videoErrorCallback" enable-danmu danmu-btn controls></video>
		</view>
		<view class="content" style="padding: 16rpx 32rpx;">
			<rich-text :nodes="repairRichText(opt.content)"></rich-text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				opt: ''
			}
		},
		onLoad(option) {
			// uni.hideHomeButton()
			if (uni.getStorageSync('config')) {
				let opt_list = uni.getStorageSync('config').opt_list;
				this.opt = opt_list.find(item => item.id == option.id)
			} else {
				this.getMent();
			}

		},
		methods: {
			videoErrorCallback: function(e) {
				uni.showModal({
					content: e.target.errMsg,
					showCancel: false
				})
			},
			repairRichText(html) {
			  let newContent = html.replace(/\<img/gi,
			    '<img style="max-width:100%;height:auto;display:block;margin-top:0;margin-bottom:0;"')
			  return newContent;
			},
			getMent() {
				uni.showLoading({
					title: '加载中...'
				})
				ment().then(res => {
					let opt_list = res.data.opt_list;
					this.opt = opt_list.find(item => item.id == option.id)
					uni.setStorageSync('config', res.data);
					uni.hideLoading()
				}).catch(() => {
					uni.hideLoading()
				});
			},
		}
	}
</script>

<style lang="scss" scoped>
.content{
	p{
		font-size: 18px;
	}
}
</style>
